package com.gange.listener;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.gange.entity.VideoVO;
import com.gange.service.VideoSearchService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class RabbitMQConsumer {
    @Autowired
    private VideoSearchService videoSearchService;
    @RabbitListener(queues = "QES")
    public void receiveD(Message message, Channel channel) throws IOException {
        String msg = new String(message.getBody());
        VideoVO videoVO = new ObjectMapper().readValue(msg, VideoVO.class);
        System.out.println("接收到消息："+videoVO);
        videoSearchService.addVideoVo(videoVO);
    }
}
